// components/redPackage/redPackage.js
var colorParse = require("../../common/color.js");

const defaultStyle = {
    mainColor: "#47B34F",
    fullScreen: false,
    style: 1
};

Component({
    /**
   * 组件的属性列表
   */
    options: {
        addGlobalClass: true
    },
    properties: {
        domain: {
            type: String,
            observer(newVal, oldVal, changePath) {
                this.setData({
                    domain: newVal
                });
            }
        },
        componentData: {
            type: Object,
            observer(newVal, oldVal, changePath) {
                this.setData({
                    redPackageData: newVal
                });
            }
        },
        componentStyle: {
            type: Object,
            observer(newVal, oldVal, changePath) {
                var redPackageStyle = this.data.redPackageStyle;
                var rgba = colorParse.hexToRgb(newVal.mainColor, .8);
                this.setData({
                    redPackageStyle: {
                        ...redPackageStyle,
                        ...newVal,
                        mainColor2: rgba
                    }
                });
            }
        },
        color_main: {
            type: String,
            observer(newVal, oldVal, changePath) {
                var rgba = colorParse.hexToRgb(newVal, .8);
                this.setData({
                    color_main2: rgba
                });
            }
        },
        redPackage: {
            type: Object,
            observer(newVal, oldVal, changePath) {
                this.setData({
                    redPackageX: newVal
                });
            }
        },
        redPackage_flag: {
            type: Boolean,
            observer(newVal, oldVal, changePath) {
                this.setData({
                    redPackage_flagX: newVal
                });
            }
        },
        redPackageChange: {
            type: Boolean,
            observer(newVal, oldVal, changePath) {
                this.setData({
                    redPackageChangeX: newVal
                });
            }
        }
    },
    /**
   * 组件的初始数据
   */
    data: {
        redPackageStyle: {
            ...defaultStyle
        },
        redPackage_flagX: false,
        redPackageChangeX: false
    },
    /**
   * 组件的方法列表
   */
    methods: {
        more(e) {},
        receiveDiscount(e) {
            var myDetail = {
                id: e.currentTarget.dataset.id
            };
            this.triggerEvent("redEvent", myDetail, {});
        }
    }
});